package com.boot.web;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.boot.entity.User;
import com.boot.service.UserService;


@Controller
public class MainController {
	@Autowired
	private UserService userSerivce;
	
      @RequestMapping("/")
      @ResponseBody
      public String home() {
        return "Hello World!";
      }
      
      @RequestMapping("/hello/{name}")
      public String hello(@PathVariable("name") String name, Model model) {
          model.addAttribute("name", name);
          return "hello";
      }
      
      @RequestMapping("/users/{userName}")
      @ResponseBody
      public Map<String,Object> getUser(@PathVariable("userName") String userName){
    	  Map<String,Object> retMap=new HashMap();
    	  User user=userSerivce.getUser(userName);
    	  
    	  retMap.put("user", user);
    	  
    	  return retMap;
    	  
      }
}